home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / XPR / Main.C_Pre210896 < prev    next >
Text File  |  1996-07-09  |  38KB  |  1,588 lines

  1. /*
  2.  
  3.    XPR door
  4.    ========
  5.  
  6.    This door provides access to the XPR Libraries for HBBS so that you can up
  7.    and download files.
  8.  
  9.    the TRANSFER door will call this most of the time.  It takes the following options
  10.  
  11.    N_ND->ActiveDoor->SystemOptions
  12.    ===============================
  13.  
  14.    None.
  15.  
  16.    dooroptions
  17.    ===========
  18.  
  19.    <xpr<lib>.library>
  20.  
  21.    TAGS [NOWAREZ] [NOSYSTEM]
  22.  
  23.    W=<upload path>         filenames are added to this if open() fails..
  24.                            note: *** MUST *** be specified BEFORE any U=<file> parameter!
  25.  
  26.    D=<download path>       you should normally only specify one place and that should
  27.                              be HBBS:Nodes/NodeX/Playpen/ (or wherever the node's playpen is..)
  28.  
  29.                             IMPORTANT:  must have trailing / or :
  30.                             --> not any more! 9/jul/1996
  31.  
  32.    U=<file to upload>      you can specify more than one of these only if the protocol
  33.                              is a batch upload protocol
  34.                              e.g.
  35.                              U=dh2:warez/miggy/hotsoft.lha
  36.                              U=dh2:warez/miggy/newsoft.lha
  37.                              ....
  38.  
  39.    S                       tells xpr to skip files that are present in the current
  40.                            conference's download directories.
  41.  
  42.    C                       tells xpr to remove users credits for transferred files
  43.  
  44.    O=<xprlibrary options>  some options for the xpr library..
  45.  
  46.    E.G.  (examples are for node 3)
  47.  
  48.      to download users tagged files and remove creds
  49.  
  50.        XPR 3 xprzmodem.library TAGS C
  51.  
  52.      get some files into the node's playpen.
  53.  
  54.        XPR 3 xprzmodem.library S D=HBBS:Nodes/Node3/PlayPen/
  55.  
  56.  
  57.    todo
  58.    ====
  59.  
  60.    move files if they are fucked as soon as they are fclose'd
  61.    also need to call background filechecker here too..
  62.  
  63.    notes
  64.    =====
  65.  
  66.    You've no idea how much hassle this door was to write..! :-)
  67.  
  68.  
  69. */
  70.  
  71. #include <exec/types.h>
  72. #include <exec/memory.h>
  73. #include <dos/dos.h>
  74. #include <clib/exec_protos.h>
  75. #include <clib/dos_protos.h>
  76. #include <clib/alib_protos.h>
  77.  
  78. #include <stdlib.h>
  79. #include <string.h>
  80. #include <stdio.h>
  81. #include <ctype.h>
  82. #include <time.h>
  83.  
  84. #include <devices/serial.h>
  85. #include <devices/timer.h>
  86.  
  87. #include <dos/dosextens.h>
  88. #include <intuition/screens.h>
  89. #include <intuition/intuition.h>
  90. #include <intuition/gadgetclass.h>
  91. #include <libraries/gadtools.h>
  92. #include <diskfont/diskfont.h>
  93. #include <utility/utility.h>
  94. #include <graphics/gfxbase.h>
  95. #include <workbench/workbench.h>
  96. #include <graphics/scale.h>
  97. #include <clib/wb_protos.h>
  98. #include <clib/intuition_protos.h>
  99. #include <clib/gadtools_protos.h>
  100. #include <clib/graphics_protos.h>
  101. #include <clib/utility_protos.h>
  102. #include <clib/diskfont_protos.h>
  103.  
  104. #include "xpr_gui.h"
  105.  
  106. #ifdef __SASC
  107. int CXBRK(void) { return(0); }
  108. int _CXBRK(void) { return(0); }
  109. void chkabort(void) {}
  110. #endif
  111.  
  112. #include <HBBS/ANSI_Codes.h>
  113. #include <HBBS/Defines.h>
  114. #include <HBBS/types.h>
  115. #include <HBBS/structures.h>
  116. #include <HBBS/hbbscommon_protos.h>
  117. #include <HBBS/hbbscommon_pragmas.h>
  118. #include <HBBS/Hbbsnode_protos.h>
  119. #include <HBBS/Hbbsnode_pragmas.h>
  120.  
  121. struct Library *HBBSCommonBase=NULL;
  122. struct Library *HBBSNodeBase=NULL;
  123. struct TextFont *HBBSFont=NULL;
  124. struct BBSGlobalData *BBSGlobal=NULL;
  125. struct NodeData *N_ND=NULL;
  126. int N_NodeNum=-1;
  127. char outstr[1024];
  128. long __near __stack=16384;
  129.  
  130. struct FileBuffer
  131. {
  132.   struct Node node; // filename in ln_Name
  133.   BPTR FH;
  134.   ULONG BytesTransferred;
  135.   ULONG BlocksTransferred;
  136.   ULONG ActualSize;
  137.   BOOL Testing;
  138.   BOOL ReadFile;
  139.  
  140. };
  141.  
  142. #include "xproto.h"  // XPR protocol stuff...
  143.  
  144.  
  145. UBYTE ZModemCancel[] =
  146. {
  147.   24,24,24,24,24,24,24,24,24,24,
  148.    8, 8, 8, 8, 8, 8, 8, 8, 8, 8
  149. };
  150.  
  151. // *** Flags
  152.  
  153. BOOL TWindowOpen=FALSE;
  154. BOOL CheckConfPaths=FALSE;
  155.   // if set then xpr_fopen() has to check all the Conf->Download paths for an existing file
  156.   // and skip it if the file already exists.
  157. BOOL TakeCreds=FALSE;
  158.  
  159. // *** File Info
  160.  
  161. struct List *UL_FileList=NULL; // a list of FileBuffer nodes..
  162. LONG UL_Files=0;
  163.  
  164. struct List *DL_FileList=NULL; // a list of FileBuffer nodes..
  165. LONG DL_Files=0;
  166.  
  167. UBYTE *DL_Path=NULL;
  168. BOOL DL_PathOK=FALSE;
  169.  
  170. UBYTE *UL_Path=NULL;
  171. BOOL UL_PathOK=FALSE;
  172.  
  173. struct FileBuffer *CurrentFile=NULL;
  174. LONG CurrentFileNum=1;
  175.  
  176. #define T_SEND 1
  177. #define T_RECEIVE 2
  178.  
  179. ULONG TransferType=0;
  180.  
  181. // ** Stuff for the XPR bit..
  182.  
  183. UBYTE *xprlibname=NULL;
  184. UBYTE *xprlibopts=NULL;
  185.  
  186. struct Library *XProtocolBase;
  187. struct XPR_IO *xio;
  188.  
  189. struct timerequest *treq;
  190. struct MsgPort *tport;
  191. char timeropen;
  192.  
  193. struct IOExtSer *xpr_serio;
  194. struct MsgPort *NewPort,*OldPort;
  195.  
  196. // ************* Misc Functions ***************
  197.  
  198. VOID cleanup(ULONG num)
  199. {
  200.   if (HBBSNodeBase)
  201.   {
  202.     HBBS_CleanUpDoor();
  203.     CloseLibrary (HBBSNodeBase);
  204.   }
  205.  
  206.   if (HBBSCommonBase)
  207.   {
  208.     HBBS_CleanUpCommon();
  209.     CloseLibrary (HBBSCommonBase);
  210.   }
  211.  
  212.   if (num) printf("Door Error = %d\n",num);
  213.  
  214.   exit(0);
  215. }
  216.  
  217. static VOID init(char *name)
  218. {
  219.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  220.   {
  221.     cleanup(1);
  222.   }
  223.  
  224.   if (!(HBBS_InitCommon()))
  225.   {
  226.     cleanup(2);
  227.   }
  228.  
  229.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  230.   {
  231.     cleanup(3);
  232.   }
  233.  
  234.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  235.   {
  236.     cleanup(4);
  237.   }
  238.   SetProgramName(name);
  239. }
  240.  
  241.  
  242. // ************* Main Door Functions ***************
  243.  
  244. // Timer Routines..
  245.  
  246. long opentimer(void)
  247. {
  248.   if (!(treq=AllocVec(sizeof(struct timerequest),MEMF_CLEAR|MEMF_PUBLIC)))
  249.   {
  250.     return(-1);
  251.   }
  252.   if(!(tport=CreateMsgPort()))
  253.   {
  254.     FreeVec(treq);
  255.     return(-1);
  256.   }
  257.   treq->tr_node.io_Message.mn_ReplyPort=tport;
  258.   if (OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest*)treq,0))
  259.   {
  260.     DeleteMsgPort(tport);
  261.     FreeVec(treq);
  262.     return(-1);
  263.   }
  264.   timeropen=1;
  265.   return(0);
  266. }
  267.  
  268. static void closetimer(void)
  269. {
  270.   if(treq)
  271.   {
  272.     if(timeropen) CloseDevice((struct IORequest*)treq);
  273.     if(tport) DeleteMsgPort(tport);
  274.     FreeVec(treq);
  275.   }
  276. }
  277.  
  278. void qtimer(ULONG micros)
  279. {
  280.   long secs=0;
  281.  
  282.   if (micros > 1000000)
  283.   {
  284.     secs = micros / 1000000;
  285.     micros = micros % 1000000;
  286.   }
  287.   treq->tr_time.tv_micro=micros;
  288.   treq->tr_time.tv_secs=secs;
  289.   treq->tr_node.io_Command=TR_ADDREQUEST;
  290.   SetSignal(0,1L<<tport->mp_SigBit);
  291.   SendIO((struct IORequest*)treq);
  292. }
  293.  
  294. BOOL GrabSerial( void )
  295. {
  296.   if(!(NewPort=CreatePort(0,0)))
  297.     return(FALSE);
  298.  
  299.   OldPort=N_ND->SerWrite->IOSer.io_Message.mn_ReplyPort;
  300.  
  301.   N_ND->SerWrite->IOSer.io_Message.mn_ReplyPort=NewPort;
  302.   N_ND->SerRead->IOSer.io_Message.mn_ReplyPort=NewPort;
  303.  
  304.   xpr_serio=N_ND->SerWrite;
  305.  
  306.   SetSignal(0,1L<<OldPort->mp_SigBit);
  307.  
  308.   return(TRUE);
  309.  
  310. }
  311.  
  312. void ReleaseSerial( void )
  313. {
  314.  
  315.   N_ND->SerWrite->IOSer.io_Message.mn_ReplyPort=OldPort;
  316.   N_ND->SerRead->IOSer.io_Message.mn_ReplyPort=OldPort;
  317.  
  318.   if (NewPort) DeletePort(NewPort);
  319. }
  320.  
  321.  
  322.  
  323. // ************* XPR Functions ***************
  324.  
  325.  
  326. LONG __saveds __asm xpr_finfo(register __a0 STRPTR FileName,register __d0 LONG InfoType)
  327. {
  328.   struct FileInfoBlock FB;
  329.   BPTR FL;
  330.   LONG result=0;
  331.  
  332. #ifdef debugmode
  333.   printf("xpr_finfo, FileName = \"%s\" type = %ld\n",FileName,InfoType);
  334. #endif
  335.  
  336.   switch (InfoType)
  337.   {
  338.     case 1:
  339.  
  340.       if (TransferType==T_RECEIVE && DL_PathOK)
  341.       {
  342.         strcpy(outstr,DL_Path);
  343.         strcat(outstr,FileName);
  344.       }
  345.       else
  346.       {
  347.         strcpy(outstr,FileName);
  348.       }
  349.  
  350.       if(FL=Lock(outstr,SHARED_LOCK))
  351.       {
  352.         if (Examine(FL,&FB))
  353.         {
  354.           result=FB.fib_Size;
  355.         }
  356.         UnLock(FL);
  357.       }
  358.       else
  359.       {
  360.         DOOR_SysopText("Lock Failed!\r\n");
  361.       }
  362.       break;
  363.  
  364.     case 2:
  365.       result = 1; // always a binary transfer
  366.       break;
  367.   }
  368. #ifdef debugmode
  369.   printf("xpr_finfo, returning = %ld\n",result);
  370. #endif
  371.   return((LONG)result);
  372. }
  373.  
  374. LONG __saveds __asm xpr_ffirst(register __a0 STRPTR Buffer,register __a1 STRPTR Pattern)
  375. {
  376.  
  377.   #ifdef debugmode
  378.   printf("xpr_ffirst, pattern = \"%s\"\n",Pattern);
  379.   #endif
  380.  
  381.   if (UL_Files)
  382.   {
  383.     CurrentFile=(struct FileBuffer*)UL_FileList->lh_Head;
  384.     CurrentFileNum=1;
  385.     strcpy(Buffer,CurrentFile->node.ln_Name);
  386.   }
  387.  
  388.   #ifdef debugmode
  389.   printf("xpr_ffirst, buffer now = \"%s\"\n",Buffer);
  390.   #endif
  391.   return(1);
  392. }
  393.  
  394. LONG __saveds __asm xpr_fnext(register __d0 LONG OldState,register __a0 STRPTR Buffer,register __a1 STRPTR Pattern)
  395. {
  396.   #ifdef debugmode
  397.   printf("xpr_fnext, OldState = %ld, pattern = \"%s\"\n",OldState,Pattern);
  398.   #endif
  399.  
  400.   if (CurrentFileNum<UL_Files)
  401.   {
  402.     CurrentFile=(struct FileBuffer*)CurrentFile->node.ln_Succ;
  403.     CurrentFileNum++;
  404.     strcpy(Buffer,CurrentFile->node.ln_Name);
  405.     #ifdef debugmode
  406.     printf("xpr_fnext, filename: %s, returning 1",Buffer);
  407.     #endif
  408.     return((LONG)1);
  409.   }
  410.   #ifdef debugmode
  411.   printf("No more files for xpr_fnext\n");
  412.   #endif
  413.   return((LONG)0);
  414. }
  415.  
  416. LONG __saveds __asm xpr_gets(register __a0 STRPTR Prompt,register __a1 STRPTR Buffer)
  417. {
  418.   #ifdef debugmode
  419.   printf("xpr_gets, Prompt = \"%s\", Buffer = \"%s\"\n",Prompt,Buffer);
  420.   #endif
  421.   return((LONG)0);
  422. }
  423.  
  424. LONG __saveds __asm xpr_fopen(register __a0 STRPTR FileName,register __a1 STRPTR AccessMode)
  425. {
  426.   BPTR FL;
  427.   BOOL FileExists=FALSE;
  428.   UBYTE tmpfilename[1024],newname[1024];
  429.   struct ConfData *Conf=NULL;
  430.   struct Node *node;
  431.   struct NodeData *nd;
  432.  
  433.   #ifdef debugmode
  434.   sprintf(outstr,"xpr_open, file = \"%s\", mode = \"%s\"\r\n",FileName,AccessMode);
  435.   DOOR_SysopText(outstr);
  436.   #endif
  437.  
  438.   if (stricmp(AccessMode,"r")==0)
  439.   {
  440.     if (TransferType==T_RECEIVE)
  441.     {
  442.       // *C* check here for existance of file in the PartUploads dir and move it to the
  443.       // playpen.. Also check in the current conference's dl_paths (if in a conf..)
  444.  
  445.       if ((CheckConfPaths) && (Conf=FindConf()))
  446.       {
  447.         for (node=Conf->Download->lh_Head;!FileExists && node->ln_Succ;node=node->ln_Succ)
  448.         {
  449.           strcpy(tmpfilename,node->ln_Name);
  450.           strcat(tmpfilename,FileName);
  451.           if (PathOK(tmpfilename)) FileExists=TRUE;
  452.         }
  453.  
  454.         if (!FileExists) // now check in the other nodes playpen dirs to see if
  455.         {                // someone else is uploading the same file..
  456.           for (nd=(struct NodeData *)BBSGlobal->NodeList->lh_Head;!FileExists && nd->node.ln_Succ;nd=(struct NodeData*)nd->node.ln_Succ)
  457.           {
  458.             strcpy(tmpfilename,nd->NodeSettings.NodePlayPen);
  459.             AddPart(tmpfilename,FileName,1024);
  460.             if (PathOK(tmpfilename)) FileExists=TRUE;
  461.           }
  462.         }
  463.  
  464.         if (!FileExists)
  465.         {
  466.           // check in partupload directory and if present copy to playpen so user can
  467.           // resume the u/l..
  468.  
  469.           for (node=Conf->PartUpload->lh_Head;!FileExists && node->ln_Succ;node=node->ln_Succ)
  470.           {
  471.             sprintf(tmpfilename,"%s%s@%ld",node->ln_Name,FileName,N_ND->User.CallData.UserID);
  472.             if (PathOK(tmpfilename))
  473.             {
  474.               strcpy(newname,DL_Path);
  475.               AddPart(newname,FileName,1024);
  476.               Rename(tmpfilename,newname);    // *C* change and add a copy here if rename fails!!
  477.               FileExists=TRUE;
  478.             }
  479.           }
  480.           FileExists=FALSE; // as we don't want to skip anymore..
  481.         }
  482.  
  483.       }
  484.  
  485.       if ((FileExists) || (!DL_PathOK))
  486.       {
  487.         // file exists, no path specified
  488.         #ifdef debugmode
  489.         puts("file exists or no dlpath");
  490.         #endif
  491.         return(0); // this will cause the file to be SKIPPED
  492.       }
  493.  
  494.       CurrentFile=NULL;
  495.  
  496.       strcpy(tmpfilename,DL_Path);
  497.       AddPart(tmpfilename,FileName,1024);
  498.  
  499.       if (CurrentFile=(struct FileBuffer*)HBBS_CreateNode(tmpfilename,sizeof(struct FileBuffer)))
  500.       {
  501.         CurrentFile->Testing=TRUE;
  502.       }
  503.     }
  504.  
  505.     if (TransferType==T_SEND)
  506.     {
  507.       if (stricmp(FileName,CurrentFile->node.ln_Name)!=0)
  508.       {
  509.         printf("Where the fuck did this filename come from ??\n: %s\n",FileName);
  510.         return(0);
  511.       }
  512.     }
  513.   }
  514.   else // transfer is a download (i.e. user sending the BBS a file.
  515.   {
  516.     // transfer is a download, so add the path of the download directory
  517.     // to the FileName
  518.  
  519.     strcpy(tmpfilename,DL_Path);
  520.     strcat(tmpfilename,FileName);
  521.  
  522.     if (CurrentFile=(struct FileBuffer*)HBBS_CreateNode(tmpfilename,sizeof(struct FileBuffer)))
  523.     {
  524.       AddTail(DL_FileList,(struct Node*)CurrentFile);
  525.       DL_Files++;
  526.     }
  527.   }
  528.  
  529.   if (!CurrentFile) // *R* needed ?
  530.   {
  531.     return(0);
  532.   }
  533.  
  534.   switch(AccessMode[0])
  535.   {
  536.     case 'r':
  537.       // open the file, if it fails and we're sending a file then add the u/l path to the filename
  538.       CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE);
  539.  
  540. /* not used here... see at param checking part of program!
  541.       if (!(CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE)))
  542.       {
  543.         if (UL_PathOK && TransferType==T_SEND)
  544.         {
  545.           FreeStr(CurrentFile->node.ln_Name);
  546.           strcpy(tmpfilename,UL_Path);
  547.           AddPart(tmpfilename,FileName,1023);
  548.           if (CurrentFile->node.ln_Name=DupStr(tmpfilename))
  549.           {
  550.             CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE);
  551.           }
  552.         }
  553.       }
  554. */
  555.       break;
  556.     case 'w':
  557.       // open file for writing, truncate old file if it exists
  558.       if (AccessMode[1]=='+')  // truncate file (well, delete it anyway)
  559.       {
  560.         if (FL = Lock(CurrentFile->node.ln_Name,ACCESS_WRITE))
  561.         {
  562.           UnLock(FL);
  563.           DeleteFile(CurrentFile->node.ln_Name);
  564.         }
  565.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_READWRITE);
  566.       }
  567.       else
  568.       {
  569.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_NEWFILE);
  570.       }
  571.       break;
  572.     case 'a':
  573.       // open file, seek to end, create new file if none exists.
  574.  
  575.       if (FL=Lock(CurrentFile->node.ln_Name,ACCESS_WRITE))
  576.       {
  577.         UnLock(FL);
  578.         if(CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_READWRITE))
  579.         {
  580.           DOOR_SysopText("seeking..");
  581.           if (Seek(CurrentFile->FH,0,OFFSET_END) == -1) // error seeking ?
  582.           {
  583.             Close(CurrentFile->FH);
  584.             CurrentFile->FH = NULL;
  585.           } else DOOR_SysopText("ok!\r\n");
  586.         }
  587.       }
  588.       else
  589.       {
  590.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_NEWFILE);
  591.       }
  592.       break;
  593.   }
  594.  
  595.   if (CurrentFile->FH==NULL) // open failed!
  596.   {
  597.     if (CurrentFile->Testing)
  598.     {
  599.       HBBS_FreeNode((struct Node*)CurrentFile,FALSE);
  600.     }
  601.     return(NULL);
  602.   }
  603.  
  604.   #ifdef debugmode
  605.   printf("xpr_fopen, returning %x\r\n",(LONG)CurrentFile);
  606.   #endif
  607.  
  608.  
  609.   return((LONG)CurrentFile);
  610. }
  611.  
  612. LONG __saveds __asm xpr_fclose(register __a0 struct FileBuffer *FileBuf)
  613. {
  614. #ifdef debugmode
  615.   printf("xpr_fclose, FileBuf->Filename = \"%s\" FileBuf->FH = %x\n",FileBuf->node.ln_Name,FileBuf->FH);
  616. #endif
  617.   if ((FileBuf) && (FileBuf->FH))
  618.   {
  619.     Close(FileBuf->FH);
  620.     if (FileBuf->Testing)
  621.     {
  622.       HBBS_FreeNode((struct Node*)FileBuf,FALSE);
  623.     }
  624.   }
  625.   return((LONG)0);
  626. }
  627.  
  628. LONG __saveds __asm xpr_fread(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 long Count,register __a1 struct FileBuffer *FileBuf)
  629. {
  630.   LONG retval;
  631. #ifdef debugmode
  632.   printf("xpr_fread, Size = %ld, Count = %ld\n",Size,Count);
  633. #endif
  634.   // check params are ok..
  635.   if (!Size)
  636.   {
  637. #ifdef debugmode
  638.     puts("xpr_fread size = 0!");
  639. #endif
  640.     return(0);
  641.   }
  642. //  if (Buffer == NULL || FileBuf==NULL || FileBuf->FH==NULL || Size==0 || Count==0) return((LONG)0);
  643.   retval=Read(FileBuf->FH,Buffer,Size*Count);
  644. #ifdef debugmode
  645.   printf("xpr_fread returning %ld\n",retval);
  646. #endif
  647.  
  648.   if (retval) FileBuf->ReadFile=TRUE; // so we can determine if a file was skipped if it was
  649.                                       // already present on the user's machine (not the sysop's)
  650.  
  651.   return(retval);
  652. }
  653.  
  654. LONG __saveds __asm xpr_fwrite(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 LONG Count,register __a1 struct FileBuffer *FileBuf)
  655. {
  656.   LONG retval;
  657. #ifdef debugmode
  658.   printf("xpr_write, Size = %ld, Count = %ld\n",Size,Count);
  659. #endif
  660.  
  661. //  return(Size * Count);
  662.  
  663.   // check params are ok..
  664. //  if (Buffer == NULL || FileBuf==NULL || FileBuf->FH==NULL || Size==0 || Count==0) return((LONG)0);
  665.   if (!Size)
  666.   {
  667. #ifdef debugmode
  668.     puts("xpr_fwrite size = 0!");
  669. #endif
  670.     return(0);
  671.   }
  672.   retval=Write(FileBuf->FH,Buffer,Size*Count);
  673. #ifdef debugmode
  674.   printf("xpr_write returning %ld\n",retval);
  675. #endif
  676.   return(retval);
  677. }
  678.  
  679. LONG __saveds __asm xpr_fseek(register __a0 struct FileBuffer *FileBuf,register __d0 LONG Offset,register __d1 LONG Origin)
  680. {
  681.   LONG Mode=-1;
  682.   LONG tmpval;
  683.  
  684. #ifdef debugmode
  685.   printf("xpr_seek, Offset = %ld, Origin = %ld\n",Offset,Origin);
  686. #endif
  687.  
  688.   // check params are ok..
  689.   if (FileBuf==NULL || FileBuf->FH==NULL) return((LONG)-1);
  690.  
  691.   switch(Origin)
  692.   {
  693.     case 0: Mode=OFFSET_BEGINNING; break;
  694.     case 1: Mode=OFFSET_CURRENT; break;
  695.     case 2: Mode=OFFSET_END; break;
  696.     default: return((LONG)-1);
  697.   }
  698.   tmpval=Seek(FileBuf->FH,Offset,Mode);
  699. #ifdef debugmode
  700.   printf("xpr_seek, seek() result = %ld\r\n",tmpval);
  701. #endif
  702.   return((tmpval==-1) ? (LONG)-1 : (LONG)0);
  703.  
  704. }
  705.  
  706. LONG __saveds __asm xpr_unlink(register __a0 STRPTR FileName)
  707. {
  708. #ifdef debugmode
  709.   printf("xpr_unlick, FileName = \"%s\"\n",FileName);
  710. #endif
  711.   return(DeleteFile(FileName));
  712. }
  713.  
  714. void xpr_closedisplay(void)
  715. {
  716. #ifdef debugmode
  717.   printf("xpr_closedisplay\n");
  718. #endif
  719.   return;
  720. }
  721.  
  722. LONG __saveds __asm xpr_displayupdate(register __a0 struct XPR_UPDATE *xu)
  723. {
  724.   long ud=xu->xpru_updatemask;
  725.   LONG tempnum;
  726.  
  727.   if(ud&XPRU_BYTES)
  728.   {
  729.     if (CurrentFile)
  730.     {
  731.       CurrentFile->BytesTransferred=xu->xpru_bytes;
  732.  
  733.       if (TWindowOpen)
  734.       {
  735.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Transferred],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_bytes,TAG_DONE);
  736.  
  737.         if (CurrentFile->ActualSize) tempnum=(LONG)((CurrentFile->BytesTransferred * 100) / CurrentFile->ActualSize); else tempnum=0;
  738.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Percent],XPRWin,NULL,GTNM_Number,(LONG)tempnum,TAG_DONE);
  739.  
  740.         tempnum=CurrentFile->ActualSize - CurrentFile->BytesTransferred;
  741.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Remaining],XPRWin,NULL,GTNM_Number,(LONG)tempnum,TAG_DONE);
  742.       }
  743.     }
  744.  
  745.   }
  746.  
  747.   if(ud&XPRU_PROTOCOL)
  748.   {
  749.     if (TWindowOpen)
  750.     {
  751.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Library],XPRWin,NULL,GTTX_Text,xu->xpru_protocol,TAG_DONE);
  752.     }
  753.   }
  754.   if(ud&XPRU_FILENAME)
  755.   {
  756.     if (TWindowOpen)
  757.     {
  758.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_File],XPRWin,NULL,GTTX_Text,xu->xpru_filename,TAG_DONE);
  759.     }
  760.   }
  761.   if(ud&XPRU_FILESIZE)
  762.   {
  763.     if (TWindowOpen)
  764.     {
  765.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Size],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_filesize,TAG_DONE);
  766.     }
  767.  
  768.     if (CurrentFile)
  769.     {
  770.       CurrentFile->ActualSize=xu->xpru_filesize;
  771.     }
  772.   }
  773.   if(ud&XPRU_MSG)
  774.   {
  775.     if (TWindowOpen)
  776.     {
  777.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Message],XPRWin,NULL,GTTX_Text,xu->xpru_msg,TAG_DONE);
  778.     }
  779.  
  780.   }
  781.   if(ud&XPRU_BLOCKS)
  782.   {
  783.     if (CurrentFile)
  784.     {
  785.       CurrentFile->BlocksTransferred=xu->xpru_blocks;
  786.     }
  787.     if (TWindowOpen)
  788.     {
  789.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Blocks],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_blocks,TAG_DONE);
  790.     }
  791.   }
  792.   if(ud&XPRU_ERRORMSG)
  793.   {
  794.     if (TWindowOpen)
  795.     {
  796.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Message],XPRWin,NULL,GTTX_Text,xu->xpru_errormsg,TAG_DONE);
  797.     }
  798.   }
  799.  
  800.   if(ud&XPRU_DATARATE)
  801.   {
  802.     if (TWindowOpen)
  803.     {
  804.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_CPS],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_datarate,TAG_DONE);
  805.     }
  806.   }
  807.   if(ud&XPRU_BLOCKSIZE)
  808.   {
  809.     if (TWindowOpen)
  810.     {
  811.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_BlockSize],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_blocksize,TAG_DONE);
  812.     }
  813.   }
  814.   if(ud&XPRU_ERRORS)
  815.   {
  816.     if (TWindowOpen)
  817.     {
  818.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Errors],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_errors,TAG_DONE);
  819.     }
  820.   }
  821.  
  822.   /*
  823.   if(ud&XPRU_ELAPSEDTIME)printf("%d Elapsed Time\n",xu->xpru_elapsedtime);
  824.   if(ud&XPRU_EXPECTTIME) printf("%d ExpectTime\n",xu->xpru_expecttime);
  825.   if(ud&XPRU_BLOCKCHECK) printf("%d Block Check\n",xu->xpru_blockcheck);
  826.   */
  827.  
  828.   return(0);
  829. }
  830.  
  831. LONG __saveds __asm xpr_swrite(register __a0 APTR Buffer,register __d0 LONG Size)
  832. {
  833. #ifdef debugmode
  834.   printf("xpr_swrite, Size = %ld\n",Size);
  835. #endif
  836.   if (Size==0)
  837.   {
  838. #ifdef debugmode
  839.     puts("xpr_swrite invalid size!");
  840. #endif
  841.     return((LONG)0);
  842.   }
  843.  
  844.   xpr_serio->IOSer.io_Length=Size;
  845.   xpr_serio->IOSer.io_Data=Buffer;
  846.   xpr_serio->IOSer.io_Command=CMD_WRITE;
  847.   SetSignal(0,1L<<NewPort->mp_SigBit);
  848.   DoIO((struct IORequest *)xpr_serio);
  849. #ifdef debugmode
  850.   printf("xpr_swrite returning %ld\n",xpr_serio->IOSer.io_Error);
  851. #endif
  852.   return((LONG)xpr_serio->IOSer.io_Error);
  853. }
  854.  
  855.  
  856. LONG __saveds __asm xpr_chk4abort(void)
  857. {
  858.   struct IntuiMessage *im=0;
  859.   LONG retval=0;
  860.  
  861.   if(TWindowOpen)
  862.   {
  863.     if (im=(struct IntuiMessage *)GetMsg(XPRWin->UserPort))
  864.     {
  865.       // We've only got one type of message, so it must be the close gadget
  866.       // being pressed!
  867.  
  868.       ReplyMsg((struct Message *)im);
  869.       retval=-1;
  870.  
  871.     }
  872.   }
  873.  
  874.   if (CarrierLost()) retval=-1;
  875.  
  876. #ifdef debugmode
  877.   printf("xpr_chkabort returning %ld\n",retval);
  878. #endif
  879.   return(retval);
  880. }
  881.  
  882.  
  883. LONG __saveds __asm xpr_sread(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 ULONG Timeout)
  884. {
  885.   ULONG flag;
  886.   long len;
  887.   ULONG nflag;
  888.  
  889. #ifdef debugmode
  890.   printf("xpr_sread, Size = %ld, Timeout = %ld\n",Size,Timeout);
  891. #endif
  892.  
  893.   if (Size==0)
  894.   {
  895. #ifdef debugmode
  896.     puts("xpr_sread invalid size");
  897. #endif
  898.     return((LONG)0);
  899.   }
  900.  
  901.   if(!Timeout)
  902.   {
  903. #ifdef debugmode
  904.     puts("notimeout specified!");
  905. #endif
  906.     xpr_serio->IOSer.io_Command=SDCMD_QUERY;
  907.     DoIO((struct IORequest *)xpr_serio);
  908.  
  909.     if(!(len=xpr_serio->IOSer.io_Actual))
  910.     {
  911.       // no data to be read..
  912. #ifdef debugmode
  913.       puts("xpr_sread no data!");
  914. #endif
  915.       return(0);
  916.     }
  917.     else
  918.     {
  919.       // some data is waiting
  920.       if(len>Size) len=Size;
  921.       xpr_serio->IOSer.io_Command=CMD_READ;
  922.       xpr_serio->IOSer.io_Data=Buffer;
  923.       xpr_serio->IOSer.io_Length=len;
  924.       DoIO((struct IORequest *)xpr_serio);
  925.  
  926.       // return amount of bytes read
  927. #ifdef debugmode
  928.       printf("xpr_sread, returning %ld\n",xpr_serio->IOSer.io_Actual);
  929. #endif
  930.       return((LONG)xpr_serio->IOSer.io_Actual);
  931.     }
  932.   }
  933.  
  934.   qtimer(Timeout);
  935.  
  936.   flag=(1L<<tport->mp_SigBit);
  937.  
  938.   if (TWindowOpen) flag|=(1L << XPRWin->UserPort->mp_SigBit);
  939.  
  940.  
  941.   xpr_serio->IOSer.io_Command=CMD_READ;
  942.   xpr_serio->IOSer.io_Data=Buffer;
  943.   xpr_serio->IOSer.io_Length=Size;
  944.  
  945.   SetSignal(0,1L<<NewPort->mp_SigBit);
  946.   SendIO((struct IORequest *)xpr_serio);
  947.   flag|=(1L<<NewPort->mp_SigBit);
  948.  
  949.   nflag=Wait(flag);
  950.  
  951.   if (nflag & (1L << XPRWin->UserPort->mp_SigBit))
  952.   {
  953. #ifdef debugmode
  954.     puts("window flag");
  955. #endif
  956.     if (xpr_chk4abort()==-1)
  957.     {
  958.       // abort everything, tidy up and return -1
  959.  
  960.       if (!CheckIO((struct IORequest *)xpr_serio))
  961.       {
  962.         AbortIO((struct IORequest *)xpr_serio);
  963.       }
  964.       WaitIO((struct IORequest *)xpr_serio);
  965.  
  966.       AbortIO((struct IORequest *)treq);
  967.       WaitIO((struct IORequest *)treq);
  968.  
  969.       // cancel the transfer!
  970.       xpr_swrite(ZModemCancel,20);
  971.  
  972. #ifdef debugmode
  973.       puts("xpr_sread, returning -1, aborted!");
  974. #endif
  975.       return((LONG)-1);
  976.     }
  977.     // if we get here then it was not a cancel message that we received from
  978.     // the window, so we can sit in the main loop abit more and wait for
  979.     // another signal..
  980.   }
  981.  
  982.   // some data arrived
  983.   if (nflag&(1L<<tport->mp_SigBit))
  984.   {
  985. #ifdef debugmode
  986.     puts("timer flag");
  987. #endif
  988.     if (!CheckIO((struct IORequest *)xpr_serio))
  989.     {
  990.       AbortIO((struct IORequest *)xpr_serio);
  991.     }
  992.     WaitIO((struct IORequest *)xpr_serio);
  993.  
  994.     AbortIO((struct IORequest *)treq);
  995.     WaitIO((struct IORequest *)treq);
  996.  
  997. #ifdef debugmode
  998.     printf("xpr_sread, returning %ld\n",xpr_serio->IOSer.io_Actual);
  999. #endif
  1000.     return((LONG)xpr_serio->IOSer.io_Actual);
  1001.   }
  1002.  
  1003.   // serial port didn't signal us, so it must be the timer, in which case
  1004.   // the serial read has timed out!
  1005.  
  1006. #ifdef debugmode
  1007.   puts("must be serial");
  1008. #endif
  1009.   if (!CheckIO((struct IORequest *)xpr_serio))
  1010.   {
  1011.     AbortIO((struct IORequest *)xpr_serio);
  1012.   }
  1013.   WaitIO((struct IORequest *)xpr_serio);
  1014.  
  1015.   // and cleanup the timer and serial requests
  1016.   AbortIO((struct IORequest *)treq);
  1017.   WaitIO((struct IORequest *)treq);
  1018.  
  1019.   // and just in case any bytes were read by the serial port, return the amount
  1020.   // would be 0 if a timeout occured and no data was read
  1021.  
  1022. #ifdef debugmode
  1023.   printf("xpr_sread, returning %ld\n",xpr_serio->IOSer.io_Actual);
  1024. #endif
  1025.   return((LONG)xpr_serio->IOSer.io_Actual);
  1026. }
  1027.  
  1028. LONG __saveds __asm xpr_sflush(void)
  1029. {
  1030. #ifdef debugmode
  1031.   printf("xpr_sflush\n");
  1032. #endif
  1033.  
  1034.   xpr_serio->IOSer.io_Command=CMD_FLUSH;
  1035.   DoIO((struct IORequest *)xpr_serio);
  1036.   return((LONG)xpr_serio->IOSer.io_Error);
  1037. }
  1038.  
  1039. #define ST_PARTYON  (1 << 0)
  1040. #define ST_PARTYODD (1 << 1)
  1041. #define ST_7WIRE  (1 << 2)
  1042. #define ST_QBREAK (1 << 3)
  1043. #define ST_RADBOOGIE  (1 << 4)
  1044. #define ST_SHARED (1 << 5)
  1045. #define ST_EOFMODE  (1 << 6)
  1046. #define ST_XDISABLED  (1 << 7)
  1047. #define ST_PARTYMARKON  (1 << 8)
  1048. #define ST_PARTYMARK  (1 << 9)
  1049. #define ST_2BITS  (1 << 10)
  1050. #define ST_READ7  (1 << 11)
  1051. #define ST_WRITE7 (1 << 12)
  1052.  
  1053. LONG __saveds __asm xpr_setserial(register __d0 LONG Status)
  1054. {
  1055.   STATIC LONG XprBauds[12] =
  1056.   {
  1057.     110,
  1058.     300,
  1059.     1200,
  1060.     2400,
  1061.     4800,
  1062.     9600,
  1063.     19200,
  1064.     31250,
  1065.     38400,
  1066.     57600,
  1067.     76800,
  1068.     115200
  1069.   };
  1070.  
  1071.   LONG Return,i;
  1072.  
  1073. #ifdef debugmode
  1074.   printf("xpr_setserial, status = %ld\n",Status);
  1075. #endif
  1076.  
  1077.   xpr_serio -> IOSer . io_Command = SDCMD_QUERY;
  1078.   DoIO((struct IORequest *)xpr_serio);
  1079.  
  1080.   Return = xpr_serio -> io_SerFlags & 0xFF;
  1081.  
  1082.   if(xpr_serio -> io_ExtFlags & SEXTF_MSPON)
  1083.     Return |= ST_PARTYMARKON;
  1084.  
  1085.   if(xpr_serio -> io_ExtFlags & SEXTF_MARK)
  1086.     Return |= ST_PARTYMARK;
  1087.  
  1088.   if(xpr_serio -> io_StopBits == 2)
  1089.     Return |= ST_2BITS;
  1090.  
  1091.   if(xpr_serio -> io_ReadLen == 7)
  1092.     Return |= ST_READ7;
  1093.  
  1094.   if(xpr_serio -> io_WriteLen == 7)
  1095.     Return |= ST_WRITE7;
  1096.  
  1097.   for(i = 0 ; i < 12 ; i++)
  1098.   {
  1099.     if(xpr_serio -> io_Baud == XprBauds[i])
  1100.     {
  1101.       Return |= (i << 16);   // uses 16MSB's of the LONGWORD for the speed ?
  1102.  
  1103.       break;
  1104.     }
  1105.   }
  1106.  
  1107.   if(Status != -1)
  1108.   {
  1109.     xpr_serio -> IOSer . io_Command = SDCMD_SETPARAMS;
  1110.  
  1111.     xpr_serio -> io_SerFlags    = Status & 0xFF;
  1112.     xpr_serio -> io_ExtFlags    = 0;
  1113.  
  1114.     if(Status & ST_PARTYMARKON)
  1115.       xpr_serio -> io_ExtFlags |= SEXTF_MSPON;
  1116.  
  1117.     if(Status & ST_PARTYMARK)
  1118.       xpr_serio -> io_ExtFlags |= SEXTF_MARK;
  1119.  
  1120.     if(Status & ST_2BITS)
  1121.       xpr_serio -> io_StopBits = 2;
  1122.     else
  1123.       xpr_serio -> io_StopBits = 1;
  1124.  
  1125.     if(Status & ST_READ7)
  1126.       xpr_serio -> io_ReadLen = 7;
  1127.     else
  1128.       xpr_serio -> io_ReadLen = 8;
  1129.  
  1130.     if(Status & ST_WRITE7)
  1131.       xpr_serio -> io_WriteLen = 7;
  1132.     else
  1133.       xpr_serio -> io_WriteLen = 8;
  1134.  
  1135.     DoIO((struct IORequest *)xpr_serio);
  1136.  
  1137.   }
  1138.  
  1139.   return(Return);
  1140.  
  1141. }
  1142. /* EOT [end of theft] */
  1143.  
  1144. void OpenTransferWindow( void )
  1145. {
  1146.   struct Screen *Scr=NULL;
  1147.  
  1148.   if (!TWindowOpen)
  1149.   {
  1150.     if (HBBSFont=OpenDiskFont( &HBBS8066 ) )
  1151.     {
  1152.       if (N_ND->ConOK && N_ND->NodeSettings.UseOwnScreen)
  1153.       {
  1154.         sprintf(outstr,"NodeWatch_%d",N_ND->NodeNum);
  1155.         Scr = LockPubScreen(outstr);
  1156.       }
  1157.       if (!Scr)
  1158.       {
  1159.         Scr = LockPubScreen( "CtrlScrn" );
  1160.       }
  1161.       if (Scr)
  1162.       {
  1163.         if (OpenWindowXPRWin(Scr)==0)
  1164.         {
  1165.           // Opened OK
  1166.           TWindowOpen=TRUE;
  1167.         }
  1168.         UnlockPubScreen( NULL, Scr);
  1169.       }
  1170.     }
  1171.   }
  1172. }
  1173.  
  1174. void CloseTransferWindow( void )
  1175. {
  1176.   if (HBBSFont) CloseFont(HBBSFont);
  1177.   if (TWindowOpen)
  1178.   {
  1179.     CloseWindowXPRWin();
  1180.     TWindowOpen=FALSE;
  1181.   }
  1182. }
  1183.  
  1184. void KeepFlushing( void )
  1185. {
  1186.   BOOL Done=FALSE;
  1187.  
  1188.   do
  1189.   {
  1190.     switch(DOOR_GetLine(GL_IMMEDIATE,'\0',1,2,NULL))
  1191.     {
  1192.       case IN_LOSSCARRIER:
  1193.       case IN_TIMEOUT:
  1194.         Done=TRUE;
  1195.         break;
  1196.     }
  1197.   } while (!Done);
  1198. }
  1199.  
  1200. void Xfer( void )
  1201. {
  1202.   if (XProtocolBase=OpenLibrary(xprlibname,0))
  1203.   {
  1204.     if (xio=(struct XPR_IO*)AllocVec(sizeof (struct XPR_IO),MEMF_CLEAR))
  1205.     {
  1206.       xio->xpr_fopen     = xpr_fopen;
  1207.       xio->xpr_fclose    = xpr_fclose;
  1208.       xio->xpr_fread     = xpr_fread;
  1209.       xio->xpr_fwrite    = xpr_fwrite;
  1210.  
  1211.       xio->xpr_swrite    = xpr_swrite;
  1212.       xio->xpr_sread     = xpr_sread;
  1213.       xio->xpr_sflush    = xpr_sflush;
  1214.       xio->xpr_setserial = xpr_setserial;
  1215.  
  1216.       xio->xpr_update    = xpr_displayupdate;
  1217.       xio->xpr_chkabort  = xpr_chk4abort;
  1218.       xio->xpr_ffirst    = xpr_ffirst;
  1219.       xio->xpr_fnext     = xpr_fnext;
  1220.       xio->xpr_finfo     = xpr_finfo;
  1221.       xio->xpr_fseek     = xpr_fseek;
  1222.       xio->xpr_gets      = xpr_gets;
  1223.       xio->xpr_unlink    = xpr_unlink;
  1224.  
  1225.       AbortSerRead();
  1226.  
  1227.       if (GrabSerial())
  1228.       {
  1229.         // from this point on DON'T USE DOOR_WriteText(), use DOOR_SysopText() instead!
  1230.         // or you will corrupt the transfer!
  1231.  
  1232.         if (opentimer()==0)
  1233.         {
  1234.  
  1235.           xio->xpr_filename=xprlibopts;
  1236.  
  1237.  
  1238. //          DOOR_SysopText("protocol options= \"");
  1239. //          if (xprlibopts) DOOR_SysopText(xprlibopts);
  1240. //          DOOR_SysopText("\"\r\n");
  1241.  
  1242.           OpenTransferWindow();
  1243.  
  1244.           if(XProtocolSetup(xio))
  1245.           {
  1246.  
  1247.             if (UL_Files) // Uploading ??
  1248.             {
  1249.               // init filename with finename of first the first..
  1250.  
  1251.               xio->xpr_filename=HBBS_ListName(UL_FileList,0);
  1252.               TransferType=T_SEND;
  1253.               XProtocolSend(xio);
  1254.             }
  1255.             else // nope, Downloading ?
  1256.             {
  1257.               if (DL_PathOK)
  1258.               {
  1259.                 // Yup...
  1260.  
  1261.                 // init filename with path to download files..
  1262.  
  1263.                 xio->xpr_filename=DL_Path;
  1264.  
  1265.                 TransferType=T_RECEIVE;
  1266.                 XProtocolReceive(xio);
  1267.               }
  1268.             }
  1269.             XProtocolCleanup(xio);
  1270.           }
  1271.  
  1272.           CloseTransferWindow();
  1273.  
  1274.           closetimer();
  1275.         }
  1276.         else
  1277.         {
  1278.           DOOR_SysopText("Failed To Open Timer!\r\n");
  1279.         }
  1280.         ReleaseSerial();
  1281.  
  1282.         KeepFlushing();
  1283.  
  1284.       }
  1285.       else
  1286.       {
  1287.         DOOR_WriteText("Failed To Open Serial!\r\n");
  1288.       }
  1289.       FreeVec(xio);
  1290.     }
  1291.     CloseLibrary(XProtocolBase);
  1292.   }
  1293.   else
  1294.   {
  1295.     DOOR_WriteText("Failed to open \"");
  1296.     DOOR_WriteText(xprlibname);
  1297.     DOOR_WriteText("\" Exiting!\r\n");
  1298.   }
  1299.  
  1300. }
  1301.  
  1302. void CheckULList(void)
  1303. {
  1304.   struct FileBuffer *node;
  1305.   struct TaggedFile *Tag;
  1306.  
  1307.   for (node = (struct FileBuffer *)UL_FileList->lh_Head ; node->node.ln_Succ ; node =(struct FileBuffer *)node->node.ln_Succ)
  1308.   {
  1309.     if (node->ActualSize==node->BytesTransferred)
  1310.     {
  1311.       N_ND->Actions[ACTN_DOWNLOAD]=ACTC_DOWNLOAD;
  1312.  
  1313.       // transferred the file ok, remove creds (if applicable)
  1314.       // and write to callers log and ul/dl log..
  1315.  
  1316.       sprintf(outstr,"DOWNLOADED File:\"%s\" Size:%ld",node->node.ln_Name,node->ActualSize);
  1317.       HBBS_AddToCallersLog(outstr);
  1318.  
  1319.       N_ND->User.CallData.ActualDownloadFiles++;
  1320.       N_ND->User.NormalData.ActualDownloadFiles++;
  1321.       N_ND->User.CallData.ActualDownloadBytes+=node->ActualSize;
  1322.       N_ND->User.NormalData.ActualDownloadBytes+=node->ActualSize;
  1323.  
  1324.       N_ND->User.FilesDownloaded++;
  1325.       N_ND->User.BytesDownloaded+=node->ActualSize;
  1326.  
  1327.       if (Tag=HBBS_FindTag(node->node.ln_Name,TRUE))
  1328.       {
  1329.         if (TakeCreds && Tag->WarezFile && node->BlocksTransferred && N_ND->User.Valid && node->ReadFile)
  1330.         {
  1331.           sprintf(outstr,ANSI_RESET ANSI_FG_CYAN "Removing "ANSI_FG_WHITE"%6ld"ANSI_FG_CYAN" credits for file: "ANSI_FG_WHITE"%s\r\n",node->ActualSize,FilePart(node->node.ln_Name));
  1332.           DOOR_WriteText(outstr);
  1333.  
  1334.           N_ND->User.CallData.DownloadFiles++;
  1335.           N_ND->User.NormalData.DownloadFiles++;
  1336.  
  1337.           N_ND->User.CallData.DownloadBytes+=Tag->FileSize;
  1338.           N_ND->User.NormalData.DownloadBytes+=Tag->FileSize;
  1339.         }
  1340.  
  1341.         // and remove the tagged file
  1342.  
  1343.         N_ND->TaggedFiles--; // first! :-)
  1344.         Remove((struct Node*)Tag);
  1345.  
  1346.         FreeStr(Tag->node.ln_Name);
  1347.         FreeVec(Tag);
  1348.       }
  1349.  
  1350.  
  1351.     }
  1352.     else
  1353.     {
  1354.       // *C* add U/D log too..
  1355.       // failed transferring that file, leave it tagged and write to the log..
  1356.       sprintf(outstr,"FAILED DOWNLOAD File:\"%s\" Size:%ld Transferred:%ld",node->node.ln_Name,node->ActualSize,node->BytesTransferred);
  1357.       HBBS_AddToCallersLog(outstr);
  1358.       N_ND->Actions[ACTN_FAILEDDOWNLOAD]=ACTC_FAILEDDOWNLOAD;
  1359.  
  1360.     }
  1361.   }
  1362. }
  1363.  
  1364. void CheckDLList(void)
  1365. {
  1366.   struct FileBuffer *node;
  1367.  
  1368.   for (node = (struct FileBuffer *)DL_FileList->lh_Head ; node->node.ln_Succ ; node =(struct FileBuffer *)node->node.ln_Succ)
  1369.   {
  1370.     if (node->ActualSize==node->BytesTransferred)
  1371.     {
  1372.       // transferred the file ok, add creds (if applicable)
  1373.       // and write to callers log and ul/dl log..
  1374.  
  1375.       N_ND->User.CallData.ActualUploadFiles++;
  1376.       N_ND->User.NormalData.ActualUploadFiles++;
  1377.       N_ND->User.CallData.ActualUploadBytes+=node->ActualSize;
  1378.       N_ND->User.NormalData.ActualUploadBytes+=node->ActualSize;
  1379.  
  1380.       N_ND->User.FilesUploaded++;
  1381.       N_ND->User.BytesUploaded+=node->ActualSize;
  1382.  
  1383.       sprintf(outstr,"UPLOADED File:\"%s\" Size:%ld",node->node.ln_Name,node->ActualSize);
  1384.       HBBS_AddToCallersLog(outstr);
  1385.       N_ND->Actions[ACTN_UPLOAD]=ACTC_UPLOAD;
  1386.  
  1387.  
  1388.     }
  1389.     else
  1390.     {
  1391.       // *C* add U/D log too..
  1392.       // failed transferring that file, leave it tagged and write to the log..
  1393.  
  1394.       N_ND->Actions[ACTN_FAILEDUPLOAD]=ACTC_FAILEDUPLOAD;
  1395.  
  1396.       sprintf(outstr,"FAILED UPLOAD File:\"%s\" Size:%ld Transferred:%ld",node->node.ln_Name,node->ActualSize,node->BytesTransferred);
  1397.       HBBS_AddToCallersLog(outstr);
  1398.  
  1399.  
  1400.       sprintf(outstr,ANSI_RESET ANSI_FG_CYAN "Moving failed file"ANSI_FG_BLUE": "ANSI_FG_WHITE"%s"ANSI_FG_CYAN" Size"ANSI_FG_BLUE": "ANSI_FG_WHITE"%ld\r\n",node->node.ln_Name,node->BytesTransferred);
  1401.       DOOR_WriteText(outstr);
  1402.  
  1403.       sprintf(outstr,"%s@%ld",node->node.ln_Name,N_ND->User.CallData.UserID);
  1404.  
  1405.       if (Rename(node->node.ln_Name,outstr))
  1406.       {
  1407.         sprintf(outstr,"%sPARTUPLOAD %s@%ld",N_ND->OnlineStatus==OS_ONLINE ? "" : "NOUSER ",FilePart(node->node.ln_Name),N_ND->User.CallData.UserID); // move NOUSER to the door's system options!!!
  1408.         DOOR_SystemDoor("MoveFile",outstr);
  1409.       }
  1410.       else
  1411.       {
  1412.         DeleteFile(node->node.ln_Name);
  1413.       }
  1414.  
  1415.     }
  1416.   }
  1417. }
  1418.  
  1419. void DoorMain(int argc,char *argv[])
  1420. {
  1421.   long loop;
  1422.  
  1423.   BOOL AddTags=0;
  1424.   BOOL SystemFiles=TRUE;
  1425.   BOOL WarezFiles=TRUE;
  1426.  
  1427.   struct TaggedFile *Tag;
  1428.   struct FileBuffer *NewFileNode;
  1429.   char tmpname[1024];
  1430.  
  1431.   BPTR FL;
  1432.   struct FileInfoBlock FB;
  1433.  
  1434.  
  1435.   if (UL_FileList=HBBS_CreateList())
  1436.   {
  1437.     if (DL_FileList=HBBS_CreateList())
  1438.     {
  1439.       xprlibname=argv[2];
  1440.  
  1441.       // add list of tagged files to our list of files to transfer..
  1442.  
  1443.  
  1444.       // then check the parameters to see if we have any other options..
  1445.       // remembering to miss out the arguments that we've already checked
  1446.       // (hence starting the loop from startparam)
  1447.  
  1448.       for(loop=3;loop<argc;loop++) // if there are any parameters then display them
  1449.       {
  1450.         switch(toupper(argv[loop][0]))
  1451.         {
  1452.           case 'S' :
  1453.             CheckConfPaths=TRUE;
  1454.             break;
  1455.  
  1456.           case 'C' :
  1457.             TakeCreds=TRUE;
  1458.             break;
  1459.  
  1460.           case 'U' :
  1461.             strcpy(tmpname,&argv[loop][2]);
  1462.             if (!(FL=Lock(tmpname,SHARED_LOCK))) // does the file exist ?
  1463.             {
  1464.               if (UL_PathOK)
  1465.               {
  1466.                 strcpy(tmpname,UL_Path);
  1467.                 strcat(tmpname,&argv[loop][2]); // same as argv[loop]+2, start at 3rd char..
  1468.                 FL=Lock(tmpname,SHARED_LOCK);
  1469.               }
  1470.             }
  1471.             if (FL)
  1472.             {
  1473.               if (Examine(FL,&FB))
  1474.               {
  1475.                 if (NewFileNode=(struct FileBuffer*)HBBS_CreateNode(tmpname,sizeof(struct FileBuffer)))
  1476.                 {
  1477.                    // all othe rparams are set to null by HBBS_CreateNode()
  1478.                   NewFileNode->ActualSize=FB.fib_Size;
  1479.                   AddTail(UL_FileList,(struct Node *)NewFileNode);
  1480.                   UL_Files++;
  1481.                 }
  1482.  
  1483.               }
  1484.               UnLock(FL);
  1485.             }
  1486.  
  1487.             break;
  1488.  
  1489.           case 'O' :
  1490.             xprlibopts=&argv[loop][2];
  1491.             break;
  1492.  
  1493.           case 'D' :
  1494.             if (!DL_PathOK) // only allowed ONE download path!
  1495.             {
  1496.               DL_Path=&argv[loop][2];
  1497.               if (PathOK(DL_Path)) DL_PathOK=TRUE;
  1498.             }
  1499.             break;
  1500.  
  1501.           case 'W' :
  1502.             if (!UL_PathOK) // only allowed ONE download path!
  1503.             {
  1504.               UL_Path=&argv[loop][2];
  1505.               if (PathOK(UL_Path)) UL_PathOK=TRUE;
  1506.             }
  1507.             break;
  1508.  
  1509.           default:
  1510.             if (stricmp(argv[loop],"TAGS")==0)
  1511.             {
  1512.               AddTags=TRUE;
  1513.             }
  1514.  
  1515.             if (stricmp(argv[loop],"NOSYSTEM")==0)
  1516.             {
  1517.               SystemFiles=FALSE;
  1518.             }
  1519.  
  1520.             if (stricmp(argv[loop],"NOWAREZ")==0)
  1521.             {
  1522.               WarezFiles=FALSE;
  1523.             }
  1524.  
  1525.             break;
  1526.  
  1527.         }
  1528.       }
  1529.  
  1530.       if (AddTags)
  1531.       {
  1532.         if (N_ND->TaggedFiles)
  1533.         {
  1534.           for (Tag=(struct TaggedFile *)N_ND->TaggedFileList->lh_Head;Tag->node.ln_Succ;Tag=(struct TaggedFile *)Tag->node.ln_Succ)
  1535.           {
  1536.             if (((Tag->WarezFile==TRUE) && (WarezFiles)) || ((Tag->WarezFile==FALSE) && (SystemFiles)))
  1537.             {
  1538.               if (NewFileNode=(struct FileBuffer*)HBBS_CreateNode(Tag->node.ln_Name,sizeof(struct FileBuffer)))
  1539.               {
  1540.                 NewFileNode->ActualSize=Tag->FileSize;
  1541.                 AddTail(UL_FileList,(struct Node*)NewFileNode);
  1542.                 UL_Files++;
  1543.               }
  1544.             }
  1545.           }
  1546.         }
  1547.       }
  1548.  
  1549.       if ((xprlibname) && ((UL_Files || DL_PathOK)) )
  1550.       {
  1551.         Xfer();
  1552.       }
  1553.       DOOR_WriteText("\r\n");
  1554.  
  1555.       CheckDLList();
  1556.       FreeStrList(DL_FileList); // then free it!
  1557.     }
  1558.     CheckULList();
  1559.     FreeStrList(UL_FileList);
  1560.  
  1561.  
  1562.     HBBS_SaveUserData(&N_ND->User.NormalData);
  1563.     // just in case the user decided to loose carrier! :-)
  1564.     // or if the bbs crashed (heaven forbid..) before the data was saved normally.
  1565.   }
  1566. }
  1567.  
  1568. int main(int argc,char *argv[])
  1569. {
  1570.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  1571.   {
  1572.     printf("Invalid/No Paramaters for door!\n");
  1573.     exit (20);
  1574.   }
  1575.   init("XPR");
  1576.  
  1577.   SetTaskPri(FindTask(0),2); // *C* make configurable!!!
  1578.  
  1579.   if (BBSGlobal=HBBS_GimmeBBS())
  1580.   {
  1581.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  1582.     {
  1583.       DoorMain(argc,argv);
  1584.     }
  1585.   }
  1586.   cleanup(0);
  1587. }
  1588.